package Lesson;

import java.util.Scanner;

public class ClassCalendar {

    public static int sumDays(int year){
        int sum1=0;
        for(int i=1900;i<year;i++){
            boolean isLeapYear=false;
            if(i%400==0||(i%4==0&&i%100!=0)){
                isLeapYear=true;
            }
            if(isLeapYear){
                sum1+=366;
            }else {
                sum1+=365;
            }
        }
        return sum1;
    }

    public static int getDays(int year,int month) {
        boolean isLeapYear = false;
        int days=0;
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            isLeapYear = true;
        }
        if (month == 1) {
            days=31;
        } else if (month == 2) {
            days = isLeapYear ? 29 : 28;
        } else if (month == 3) {
            days = 31;
        } else if (month == 4) {
            days = 30;
        } else if (month == 5) {
            days = 31;
        } else if (month == 6) {
            days = 30;
        } else if (month == 7) {
            days = 31;
        } else if (month == 8) {
            days = 31;
        } else if (month == 9) {
            days = 30;
        } else if (month == 10) {
            days = 31;
        } else if (month == 11) {
            days = 30;
        } else if (month == 12) {
            days = 31;
        }
        return days;
    }

     public static int monthDays(int year,int month){
        int sum=0;
        for(int i=1;i<month;i++){
            sum=sum+getDays(year,i);
        }
        return sum;
     }

     public static void printCalendar(int year,int month,int star){
        System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日\t");
        int count=0;
        for (int i=0;i<star;i++){
            System.out.print("\t\t");
            count++;
        }
        int days1=getDays(year,month);
        for(int i=1;i<=days1;i++){
            System.out.print(i+"\t\t");
            count++;
            if(count%7==0){
                System.out.println();
            }
        }
     }


    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        System.out.println("输入年份：");
        int y=scan.nextInt();
        System.out.println("输入月份：");
        int m=scan.nextInt();
        sumDays(y);
        int a=sumDays(y);
        System.out.println(sumDays(y));
        getDays(y,m);
        System.out.println(getDays(y,m));
        monthDays(y,m);
        int c=monthDays(y,m);
        System.out.println(monthDays(y,m));
        int star=(a+c)%7;
        printCalendar(y,m,star);
    }

}
